package com.ruoyi.web.controller.trade;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.trade.domain.DeliveryDate;
import com.ruoyi.trade.service.IDeliveryDateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 交割日Controller
 * 
 * @author ruoyi
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/trade/deliveryDate")
public class DeliveryDateController extends BaseController
{
    @Autowired
    private IDeliveryDateService deliveryDateService;

    /**
     * 查询交割日列表
     */
    @PreAuthorize("@ss.hasPermi('trade:deliveryDate:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeliveryDate deliveryDate)
    {
        startPage();
        List<DeliveryDate> list = deliveryDateService.selectDeliveryDateList(deliveryDate);
        return getDataTable(list);
    }

    /**
     * 导出交割日列表
     */
    @PreAuthorize("@ss.hasPermi('trade:deliveryDate:export')")
    @Log(title = "交割日", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeliveryDate deliveryDate)
    {
        List<DeliveryDate> list = deliveryDateService.selectDeliveryDateList(deliveryDate);
        ExcelUtil<DeliveryDate> util = new ExcelUtil<DeliveryDate>(DeliveryDate.class);
        util.exportExcel(response, list, "交割日数据");
    }

    /**
     * 获取交割日详细信息
     */
    @PreAuthorize("@ss.hasPermi('trade:deliveryDate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deliveryDateService.selectDeliveryDateById(id));
    }

    /**
     * 新增交割日
     */
    @PreAuthorize("@ss.hasPermi('trade:deliveryDate:add')")
    @Log(title = "交割日", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeliveryDate deliveryDate)
    {
        return toAjax(deliveryDateService.insertDeliveryDate(deliveryDate));
    }

    /**
     * 修改交割日
     */
    @PreAuthorize("@ss.hasPermi('trade:deliveryDate:edit')")
    @Log(title = "交割日", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeliveryDate deliveryDate)
    {
        return toAjax(deliveryDateService.updateDeliveryDate(deliveryDate));
    }

    /**
     * 删除交割日
     */
    @PreAuthorize("@ss.hasPermi('trade:deliveryDate:remove')")
    @Log(title = "交割日", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deliveryDateService.deleteDeliveryDateByIds(ids));
    }
}
